{php include wl_template('common/header');}
<ul class="nav nav-tabs">
	<li {if $operation == 'display'} class="active" {/if}><a href="{php echo web_url('goods/coupon_record',array('op' =>'display'))}">优惠券记录列表</a></li>
	<li {if $operation == 'prize'} class="active" {/if}><a href="{php echo web_url('goods/coupon_record',array('op' =>'prize'))}">发奖记录</a></li>
	<!--<li{if empty($prize['id']) && $operation == 'prize_post'} class="active" {/if}><a href="{php echo web_url('goods/coupon_record',array('op' =>'prize_post'))}">添加发奖</a></li>-->
	{if !empty($prize['id']) &&  $operation == 'prize_post'}<li class="active"><a href="{php echo web_url('goods/coupon_record',array('op' =>'prize_post','id'=>$prize['id']))}">编辑发奖记录</a></li>{/if}
</ul>

{if $operation == 'display'}

<div class="main panel panel-default" style="position:relative;">

	<div class="panel-body table-responsive">
		<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
			<input type="hidden" name="c" value="site" />
			<input type="hidden" name="a" value="entry" />
			<input type="hidden" name="m" value="lexiangpingou" />
			<input type="hidden" name="do" value="goods" />
			<input type="hidden" name="ac" value="coupon_record" />
			<input type="hidden" name="op" value=""/>
			<div class="form-group">
				<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">卡券信息</label>
				<div class="col-xs-12 col-sm-4 col-md-4 col-lg-2">
					<input class="form-control" name="coupon" type="text" value="{$c}" placeholder="可模糊查询优惠券名">
				</div>
				<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">用户信息</label>
				<div class="col-xs-12 col-sm-4 col-md-4 col-lg-3">
					<input class="form-control" name="member" type="text" value="{$_GPC['member']}" placeholder="模糊查询用户姓名、手机号、身份证">
				</div>
				<div class="col-xs-12 col-sm-4 col-md-2 col-lg-2">
					<select name="status" class="form-control">
						<option value="">--所有--</option>
						<option value="3">未核销</option>
						<option value="1">已核销</option>
						<option value="2">已领奖</option>
					</select>
				</div>
				<div class="col-xs-12 col-sm-4 col-md-4 col-lg-1" style="text-align:right;">
					<button class="btn btn-default min-width searchMH"><i class="fa fa-search"></i> 搜索</button>
					<input type="hidden" name="token" value="{$_W['token']}" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">日期</label>
				<div class="col-sm-4">
					<?php
					if (empty($start)){
						$start = time() - 30 * 24 * 60 * 60;
						$end = time() + 24 * 60 * 60;
					}
					?>
					{php echo tpl_form_field_daterange('time', array('start'=>date('Y-m-d H:i:s', $start),'end'=>date('Y-m-d H:i:s', $end)));}
				</div>
			</div>
		</form>
	</div>
	<div class="form-group" style="display: inline-block;position:absolute;top: 15px; right: 20px;">
		<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label" style="text-align: right;padding-right: 30px;padding-top: 10px;"></label>
		<a href='{php echo web_url('goods/coupon_record', array('op' => 'output','coupon'=>$_GPC['coupon'],'member'=>$_GPC['member']))}'>
		<button class="btn btn-info"><i class="fa fa-download"></i>导出花名册</button>
		</a>
	</div>

	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width:5%;">ID</th>
					<!--<th style="width:15%;">昵称</th>-->
					<th style="width:10%;">真实姓名</th>
					<th style="width:5%;">性别</th>
					<th style="width:20%;">手机号</th>
					<th style="width:15%;">身份证号</th>
					<th style="width:20%;">领取优惠券名称</th>
					<th style="width:11%;">剩余/已核销次数</th>
					<th style="width:14%;text-align: center">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
					<td>{$item['id']}</td>
					<!--<td>{$item['user']['nickname']}</td>-->
					<td>{$item['user']['realname']}</td>
					<td>{$item['user']['sex']}</td>
					<td>{$item['mobile']}</td>
					<td>{$item['idcard']}</td>
					<td>{$item['coupon']['name']}</td>
					<td>{$item['times']}/{$item['hexiao']}</td>
					<td class="text-center">
						{if $item['status'] == '0'}
							<a href="{php echo web_url('order/hexiao',array('op' =>'coupon','openid' => $item['openid'] , 'id' => $item['id']))}">核销</a>&nbsp;&nbsp;
						{elseif $item['prize'] == 0}
							<a href="{php echo web_url('goods/coupon_record',array('op' =>'prize_post','idcard' => $item['idcard'] , 'favorabler_id' => $item['id']))}">发奖</a>&nbsp;&nbsp;
						{else}
							<span style="color:red;">已领奖&nbsp;&nbsp;</span>
						{/if}
						<!--<a href="{php echo web_url('goods/coupon', array('op' => 'post', 'id' => $coupon['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>-->
						<a href="javascript:;" c-id="{$item['id']}" class="btn btn-default btn-sm js-delete" data-toggle="tooltip" data-placement="top" title="删除"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}

				{if !empty($item)}

				<tr>
					{if !empty($pager)}
						<td colspan="7" style="text-align: left;">{$pager}</td>
						<td colspan="1">总计共有{$total}条记录</td>
					{else}
						<td colspan="8">总计共有{$total}条记录</td>
					{/if}
				</tr>

				<tr>
					<!--<td><input type="checkbox" name="checkall" value="id[]" id="checkall" onclick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});" /></td>-->
					<!--<td colspan="4" class="text-right"><a href="javascript:;" class="btn btn-danger min-width js-batch">批量删除</a></td>-->
					<!--<td colspan="7"><a href="javascript:;" class="btn btn-danger min-width js-deleteAll">全部删除</a></td>-->
				</tr>
				{else}
				<tr>
					<td colspan="8" style="text-align: center"><span style="color:red;font-size: 16px;">优惠券记录为空</span></td>
				</tr>
				{/if}
			</tbody>
		</table>
	</div>
</div>
<script>
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
	$(function(){
        $(".scrollLoading").scrollLoading();
        var $pop = null;
        $('.scrollLoading').hover(function(){
            var img = $(this).attr('src');
            var obj = this;
            var $pop = util.popover(obj, function($popover, obj){
                obj.$popover = $popover;
            }, '<div><img src="'+img+'" style="max-width:200px; max-height:200px;"></div>');
        }, function(){
            this.$popover.remove();
        });
        $('.js-delete').click(function(e) {
            e.stopPropagation();
            var cid = $(this).attr('c-id');
            var $this = $(this);
            util.nailConfirm(this, function(state) {
                if (!state) {
                    return;
                }
                $.post("{php echo web_url('goods/coupon_record/delete')}", {id : cid}, function(data) {
                    if(!data.errno){
                        $this.parent().parent().remove();
                    };
                    util.tips(data.message);
                }, 'json');
            });
        });
    });
</script>
{elseif $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="id" value="{$coupon['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">
				优惠券管理
			</div>
			<div class="panel-body">
				<!--<div class="form-group">-->
					<!--<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>-->
					<!--<div class="col-sm-9 col-xs-12">-->
						<!--<input type="text" name="id" class="form-control" value="{$coupon['id']}" />-->
					<!--</div>-->
				<!--</div>-->
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>优惠券名字</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" id='couponname' name="name" class="form-control" value="{$coupon['name']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠券小标题</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="subtitle" class="form-control" value="{$coupon['subtitle']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">当前报名人数</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="applicant" class="form-control" value="{$coupon['applicant']}" />
					</div>
				</div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">报名人数上限</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="up_limit" class="form-control" value="{$coupon['up_limit']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">报名截止日期</label>
					<div class="col-sm-3 col-xs-4">
						{php echo tpl_form_field_date('deadline', $coupon['deadline'] , true)}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">开始时间</label>
					<div class="col-sm-3 col-xs-4">
						{php echo tpl_form_field_date('start_time' , $coupon['start_time'] , true);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">结束时间</label>
					<div class="col-sm-3 col-xs-4">
						{php echo tpl_form_field_date('end_time' , $coupon['end_time'] , true);}
					</div>
				</div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">开课时间:</label>
					<div class="col-sm-9 col-xs-12" style="position:relative">
						{php echo tpl_ueditor('class_time', $coupon['class_time']);}
					</div>
                </div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠券图片</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('pic', $coupon['pic'])}
						<span class="help-block">建议尺寸大小640*400px</span>
					</div>

				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">适用人群</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="person" class="form-control" value="{$coupon['person']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">课程介绍:</label>
					<div class="col-sm-9 col-xs-12" style="position:relative">
						{php echo tpl_ueditor('course', $coupon['course']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">上课地址</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="address" class="form-control" value="{$coupon['address']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">使用须知:</label>
					<div class="col-sm-9 col-xs-12" style="position:relative">
						{php echo tpl_ueditor('term', $coupon['term']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">核销员</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="salesman" class="form-control" value="{$coupon['salesman']}" />
					</div>
				</div>
			</div>
		</div>
<div class="form-group col-sm-12">
	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
	<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
	</form>
</div>

<script language='javascript'>
	function formcheck() {
		if ($("#couponname").isEmpty()) {
			Tip.focus("couponname", "请填写优惠券名称!");
			return false;
		}
		return true;
	}

	$('.searchMH').click(function(){
		var s=$('#searchMH').val();
		if(s==""){
			return false;
		}
		$.get('',{keyword:s},function(){

		})
	})
</script>

{elseif $operation == 'prize'}
<div class="main panel panel-default" style="position:relative;">

	<!--<div class="panel-body table-responsive">-->
		<!--<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">-->
			<!--<input type="hidden" name="c" value="site" />-->
			<!--<input type="hidden" name="a" value="entry" />-->
			<!--<input type="hidden" name="m" value="lexiangpingou" />-->
			<!--<input type="hidden" name="do" value="goods" />-->
			<!--<input type="hidden" name="ac" value="coupon_record" />-->
			<!--<input type="hidden" name="op" value=""/>-->
			<!--<input type="hidden" name="coupon" value="{$coupon}"/>-->
			<!--<input type="hidden" name="member" value="{$member}"/>-->
			<!--<div class="form-group">-->
				<!--<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">卡券信息</label>-->
				<!--<div class="col-xs-12 col-sm-4 col-md-4 col-lg-3">-->
					<!--<input class="form-control" name="coupon" type="text" value="{$c}" placeholder="可模糊查询优惠券名">-->
				<!--</div>-->
				<!--<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">用户信息</label>-->
				<!--<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">-->
					<!--<input class="form-control" name="member" type="text" value="{$_GPC['member']}" placeholder="可模糊查询用户姓名、手机号、身份证号">-->
				<!--</div>-->

				<!--<div class="col-xs-12 col-sm-4 col-md-4 col-lg-1" style="text-align:right;">-->
					<!--<button class="btn btn-default min-width searchMH"><i class="fa fa-search"></i> 搜索</button>-->
					<!--<input type="hidden" name="token" value="{$_W['token']}" />-->
				<!--</div>-->
			<!--</div>-->
		<!--</form>-->
	<!--</div>-->
	<!--<div class="form-group" style="display: inline-block;position:absolute;top: 15px; right: 20px;">-->
		<!--<label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label" style="text-align: right;padding-right: 30px;padding-top: 10px;"></label>-->
		<!--<a href='{php echo web_url('goods/coupon_record', array('op' => 'output','coupon'=>$_GPC['coupon'],'member'=>$_GPC['member']))}'>-->
		<!--<button class="btn btn-info"><i class="fa fa-download"></i>导出花名册</button>-->
		<!--</a>-->
	<!--</div>-->

	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
			<tr>
				<th style="width:2%;">ID</th>
				<!--<th style="width:15%;">昵称</th>-->
				<th style="width:15%;">真实姓名</th>
				<th style="width:5%;">性别</th>
				<th style="width:10%;">手机号</th>
				<th style="width:20%;">身份证号</th>
				<th style="width:10%;">总活动次数</th>
				<!--<th style="width:10%;">发奖时活动次数</th>-->
				<th style="width:13%;">发奖时间</th>
				<th style="width:10%;text-align: center">操作</th>
			</tr>
			</thead>
			<tbody>
			{loop $list $item}
			<tr>
				<td>{$item['id']}</td>
				<!--<td>{$item['user']['nickname']}</td>-->
				<td>{$item['user']['realname']}</td>
				<td>{$item['user']['sex']}</td>
				<td>{$item['user']['mobile']}</td>
				<td>{$item['user']['idcard']}</td>
				<td>{$item['times']}</td>
				<!--<td>{$item['prize_times']}</td>-->
				<td>{php echo date('Y-m-d H:i',$item['prize_time'])}</td>
				<td style="text-align: center">
					<!--<a href="{php echo web_url('goods/coupon_record', array('op' => 'prize_post', 'id' => $item['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>-->
					<a href="javascript:;" c-id="{$item['id']}" class="btn btn-default btn-sm js-delete" data-toggle="tooltip" data-placement="top" title="删除"><i class="fa fa-times"></i></a>
				</td>
			</tr>
			{/loop}

			{if !empty($item)}

			<tr>
				{if !empty($pager)}
				<td colspan="6" style="text-align: left;">{$pager}</td>
				<td colspan="2">总计共有{$total}条记录</td>
				{else}
				<td colspan="8">总计共有{$total}条记录</td>
				{/if}
			</tr>

			<tr>
				<!--<td><input type="checkbox" name="checkall" value="id[]" id="checkall" onclick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});" /></td>-->
				<!--<td colspan="4" class="text-right"><a href="javascript:;" class="btn btn-danger min-width js-batch">批量删除</a></td>-->
				<!--<td colspan="7"><a href="javascript:;" class="btn btn-danger min-width js-deleteAll">全部删除</a></td>-->
			</tr>
			{else}
			<tr>
				<td colspan="8" style="text-align: center"><span style="color:red;font-size: 16px;">发奖记录为空</span></td>
			</tr>
			{/if}
			</tbody>
		</table>
	</div>
</div>
<script>
    require(['bootstrap'],function($){
        $('.btn').hover(function(){
            $(this).tooltip('show');
        },function(){
            $(this).tooltip('hide');
        });
    });
    $(function(){
        $(".scrollLoading").scrollLoading();
        var $pop = null;
        $('.scrollLoading').hover(function(){
            var img = $(this).attr('src');
            var obj = this;
            var $pop = util.popover(obj, function($popover, obj){
                obj.$popover = $popover;
            }, '<div><img src="'+img+'" style="max-width:200px; max-height:200px;"></div>');
        }, function(){
            this.$popover.remove();
        });
        $('.js-delete').click(function(e) {
            e.stopPropagation();
            var cid = $(this).attr('c-id');
            var $this = $(this);
            util.nailConfirm(this, function(state) {
                if (!state) {
                    return;
                }
                $.post("{php echo web_url('goods/coupon_record/prize_delete')}", {id : cid}, function(data) {
                    if(!data.errno){
                        $this.parent().parent().remove();
                    };
                    util.tips(data.message);
                }, 'json');
            });
        });
    });
</script>
{elseif $operation == 'prize_post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="id" value="{$prize['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">
				发奖管理
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>获奖人身份证号</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" id='' name="idcard" class="form-control" value="{$prize['idcard']}" />
					</div>
				</div>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>

{/if}
{php include wl_template('common/footer');}